From: Wei Liu Date: Wed, 25 Feb 2015 14:56:01 +0000 (+0000) Subject: gentest: make testidl valgrind clean X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~3685 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22?a=commitdiff_plain;h=6d8261111b1c8836b6ce98df205ffc3334340fd7;p=xen.git gentest: make testidl valgrind clean Free the JSON string after use to avoid memory leak. With this change testidl is valgrind clean. Signed-off-by: Wei Liu Cc: Ian Campbell Cc: Ian Jackson Acked-by: Ian Campbell --- diff --git a/tools/libxl/gentest.py b/tools/libxl/gentest.py index 95323d1de9..849bfc7a2f 100644 --- a/tools/libxl/gentest.py +++ b/tools/libxl/gentest.py @@ -229,7 +229,7 @@ int main(int argc, char **argv) (ty.typename, ty.typename, ty.typename)) f.write(""" int rc; - char *s, *new_s; + char *s, *new_s, *json_string; xentoollog_logger_stdiostream *logger; libxl_ctx *ctx; @@ -323,9 +323,13 @@ int main(int argc, char **argv) f.write(" printf(\"%s -- to JSON:\\n\");\n" % (ty.typename)) for v in ty.values: + f.write(" json_string = %s_to_json(ctx, %s);\n" % \ + (ty.typename, v.name)) f.write(" printf(\"\\t%s = %%d = %%s\", " \ - "%s, %s_to_json(ctx, %s));\n" %\ - (v.valuename, v.name, ty.typename, v.name)) + "%s, json_string);\n" %\ + (v.valuename, v.name)) + f.write(" free(json_string);\n"); + f.write(" json_string = NULL;\n"); f.write("\n") f.write(" printf(\"%s -- from string:\\n\");\n" % (ty.typename))